package com.shxc.smarttrade.old.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.myview.CommonDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by jcdev1 on 2017/11/8.
 */

public class RelationUsActivity extends BaseActivity {
    @BindView(R.id.tv_center)
    TextView tvCenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_relation_us);
        initView();
    }

    private void initView() {
        tvCenter.setText("联系我们");
    }

    @OnClick({R.id.rl_left, R.id.ll_official_websit, R.id.ll_official_webchart, R.id.ll_qq, R.id.ll_telephone})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_left:
                finish();
                break;
            case R.id.ll_official_websit:
                //从其他浏览器打开
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri content_url = Uri.parse("http://www.trademaster168.com");
                intent.setData(content_url);
                startActivity(Intent.createChooser(intent, "请选择浏览器"));
                break;
            case R.id.ll_official_webchart:
                showCustomerService(0);
                break;
            case R.id.ll_qq:
                showCustomerService(1);
                break;
            case R.id.ll_telephone:
                Uri uri = Uri.parse("tel:" + "0571-58239809");
                Intent dialntent = new Intent(Intent.ACTION_DIAL, uri);
                startActivity(dialntent);
                break;
        }
    }


    private void showCustomerService(final int tag) {
        CommonDialog commonDialog = new CommonDialog(this, R.style.customDialogStyle);
        commonDialog.setCanceledOnTouchOutside(true);
        commonDialog.setBaseText("提示", "是否复制？", "取消", "确定");
        commonDialog.setYesCLickRunAble(new Runnable() {
            @Override
            public void run() {

                if (tag == 0) {//复制微信
                    cliboardText("whjyds168");

                } else if (tag == 1) {//复制QQ
                    cliboardText("798030775");
                }
            }
        });
        commonDialog.show();
    }

    /**
     * 粘贴
     *
     * @param text
     */
    private void cliboardText(String text) {
        ClipboardManager clipboard = (ClipboardManager)
                getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("webChart", text);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
    }
}
